;; yassnipet
(require 'yasnippet-bundle)
(setq yas/root-directory
      (concat config-base-path "snippets"))
(yas/load-directory yas/root-directory)

;; ecb
(ray-add-path "plugins/ecb-2.40")
(require 'ecb-autoloads)
;(global-set-key (kbd "<F1>") ecb-toggle-ecb-windows)

;; cedet
;; load cedet.el multiple times will cause a error
(condition-case nil
    (ray-load-file "plugins/cedet-1.0/common/cedet.el")
  (error nil))
(global-ede-mode 1)
(semantic-load-enable-code-helpers)
(global-semantic-decoration-mode 1)
(global-semantic-idle-completions-mode 1)

;; highlight symbol current selected
(require 'highlight-symbol)

(require 'semantic-ia)
(require 'semantic-gcc)
(require 'semanticdb)
(semantic-add-system-include "~/proj/include" 'c++-mode)
(global-semanticdb-minor-mode 1)

(setq semanticdb-default-save-directory
      (expand-file-name
       (concat config-base-path "semanticdb")))

;; show function name at buffer line
(which-func-mode)

;; visible bookmark
(enable-visual-studio-bookmarks)

;; ;; How to use it?
;; (global-srecode-minor-mode 1)

;; set semantic include paths
(defconst cedet-user-include-dirs
  (list "."
        ".."
        "../include"
        "../inc"
        "../common"
        "../.."
        "../../include"
        "../../inc"
        "../../common"
        "../../proj"))

(require 'semantic-c nil 'noerror)
(let ((include-dirs cedet-user-include-dirs))
  (mapc (lambda (dir)
          (semantic-add-system-include dir 'c++-mode)
          (semantic-add-system-include dir 'c-mode))
        include-dirs))

;; Go back to original place from function definition
(defun def-goback()
  (interactive)
  (if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
      (error "Semantic Bookmark ring is current empty"))
  (let* ((ring (oref semantic-mru-bookmark-ring ring))
         (alist (semantic-mrub-ring-to-assoc-list ring))
         (first (cdr (car alist))))
    (if (semantic-equivalent-tag-p (oref first tag)
                                   (semantic-current-tag))
        (setq first (cdr (car (cdr alist)))))
    (semantic-mrub-switch-tags first)))
